// pages/notice/notice.js
var utils = require('../../../utils/util.js') 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data:[],
    page:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  //下拉刷新
  onPullDownRefresh: function () {
    this.setData({
      data: [],
      page: 1,
    });
    this.onShow();
  },
  //上拉加载
  onReachBottom: function () {
    this.onShow();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var userinfo = wx.getStorageSync("userinfo");
    var token = userinfo.wap_token;
    var data = {
      url: "/v1/commessage/lists",
      token: token,
      page: that.data.page,
      limit: 10
    };
    utils.request(data).then(function (res) {
      if (res.data.length > 0) {
        that.setData({
          page: that.data.page + 1
        });
      }
      that.setData({
        data: that.data.data.concat(res.data)
      })
      wx.stopPullDownRefresh();
      
    });
  },

})